package model;

import java.io.IOException;

import nom.tam.fits.BasicHDU;
import nom.tam.fits.Fits;
import nom.tam.fits.FitsException;

@SuppressWarnings("serial")
public class FitsFile{
	
	public FitsFile(String filePath){
		this.filePath = filePath;
	}
	String filePath;
	String filename;String folder;String survey;String telescope;String author;String origin;
	String observer;double equinox;String ctype1;String ctype2;double crval1;double crval2;
	
	public void extractMetadata(String survey){
		
		Fits fits = null;
		try {
			fits = new Fits(this.filePath);
	
		BasicHDU newBasicHDU = null;
		int startIndex=0;
		if(java.lang.System.getProperty("os.name").equals("Unix")||java.lang.System.getProperty("os.name").equals("Linux")){
			 startIndex = this.filePath.lastIndexOf('/');
		}
		if(java.lang.System.getProperty("os.name").equals("Windows Vista")){	
			startIndex = this.filePath.lastIndexOf('\\');
		}

		this.filename = this.filePath.substring(startIndex + 1);
		this.folder = this.filePath.substring(0,startIndex+1);
		
			while((newBasicHDU = fits.readHDU())!= null){
				
				this.setSurvey(survey);
				this.setAuthor(newBasicHDU.getAuthor());
				this.setTelescope(newBasicHDU.getTelescope());
				this.setObserver(newBasicHDU.getObserver());
				this.setOrigin(newBasicHDU.getOrigin()); 
				this.setEquinox(newBasicHDU.getEquinox());
				this.setCtype1(newBasicHDU.getCType1());
				this.setCtype2(newBasicHDU.getCType2());
				this.setCrval1(newBasicHDU.getCRVal1());
				this.setCrval2(newBasicHDU.getCRVal2());		
			}
		} catch (FitsException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public String getFilename() {
		return filename;
	}


	public void setFilename(String filename) {
		this.filename = filename;
	}


	public String getFolder() {
		return folder;
	}


	public void setFolder(String folder) {
		this.folder = folder;
	}


	public String getSurvey() {
		return survey;
	}


	public void setSurvey(String survey) {
		this.survey = survey;
	}


	public String getTelescope() {
		return telescope;
	}


	public void setTelescope(String telescope) {
		this.telescope = telescope;
	}


	public String getAuthor() {
		return author;
	}


	public void setAuthor(String author) {
		this.author = author;
	}


	public String getObserver() {
		return observer;
	}


	public void setObserver(String observer) {
		this.observer = observer;
	}


	public String getOrigin() {
		return origin;
	}

	public void setOrigin(String origin) {
		this.origin = origin;
	}

	public double getEquinox() {
		return equinox;
	}


	public void setEquinox(double equinox) {
		this.equinox = equinox;
	}


	public String getCtype1() {
		return ctype1;
	}


	public void setCtype1(String ctype1) {
		this.ctype1 = ctype1;
	}


	public String getCtype2() {
		return ctype2;
	}


	public void setCtype2(String ctype2) {
		this.ctype2 = ctype2;
	}


	public double getCrval1() {
		return crval1;
	}


	public void setCrval1(double crval1) {
		this.crval1 = crval1;
	}


	public double getCrval2() {
		return crval2;
	}


	public void setCrval2(double crval2) {
		this.crval2 = crval2;
	}
}
